package com.restfinder.common.component.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUtils {

	public static String getAuthenticatedUsername(){
		Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username;
        if (obj instanceof UserDetails) {
                username = ((UserDetails) obj).getUsername();
        } else {
                username = obj.toString();
        }
        return username;
	}
	
	public static void setAuthentication(Authentication authenticate) {
		SecurityContextHolder.getContext().setAuthentication(authenticate);
	}
}
